# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# from AUR - adjusted to our styles
#
# Maintainer: grufo <madmurphy333 AT gmail DOT com>
# Maintainer: Sebastian Jug <seb AT stianj DOT ug>
# Contributor: midgard <arch.midgard AT janmaes DOT com>
# Contributor: TrialnError <autumn-wind AT web DOT de>
# Contributor: Yardena Cohen <yardenack AT gmail DOT com>
# Contributor: Max Roder <maxroder AT web DOT de>
# Contributor: BrLi

pkgname=tor-browser
pkgver=15.0.2
pkgrel=1
pkgdesc='Tor Browser Bundle: anonymous browsing using Firefox and Tor.'
groups=('blackarch' 'blackarch-defensive')
url='https://www.torproject.org/projects/torbrowser.html'
license=('GPL')
depends=('libxt' 'startup-notification' 'mime-types' 'dbus-glib' 'alsa-lib'
         'desktop-file-utils' 'hicolor-icon-theme' 'libvpx' 'icu' 'libevent'
         'nss' 'hunspell' 'sqlite')
optdepends=('zenity: simple dialog boxes'
            'kdialog: KDE dialog boxes'
            'gst-plugins-good: H.264 video'
            'gst-libav: H.264 video'
            'libpulse: PulseAudio audio driver'
            'libnotify: Gnome dialog boxes')
provides=("$pkgname")
conflicts=("$pkgname")
install="$pkgname.install"
_urlbase="https://dist.torproject.org/torbrowser/${pkgver}"
_archstr="x86_64"
arch=('x86_64')
source=("$_urlbase/$pkgname-linux-$_archstr-$pkgver.tar.xz"
        "$pkgname.desktop.in"
        "$pkgname.in"
        "$pkgname.png"
        "$pkgname.svg")
noextract=("$pkgname-linux-$_archstr-$pkgver.tar.xz")
sha512sums=('b865774c0da4d7ab82eb42d9fc829fa4287596da4021b0eb8319e43e01ad1cd27c52e9204eac554dbd6a2b67b1df87e2e52086452ed2e6fc4de751e86a4fd5b0'
            '909d72393acbfe1123ead9450e14bef35fb570e5488982e46632a21734990a2cffdcba74f6e0d62eac78aa183c5778b57951ccd1095e46b910cbd860277f0259'
            '8c656941749238d1e4b0549cc0f2ca37c103a4e57422ac1f25ea147ab396b843c0613569ced0f3418ae9be5a8d5158d7d3da8be153a1da01f460625eced46e7e'
            'e334c1f226235c30011e62602ec0c0bd549bfe411e37125a5ee47f2a2d187045bc261efcaf2a9490d01dc687878ecfe01827996adc62e76df39ee8146d76713e'
            '662b800e849f2fa369496974d0e22c68cb5f5666cb8d3f768d236daae40c693880fb051f860aacf347a0fc8491764a315053dc9bbcc149f820267d1466bd995a')

# Make a string suitable for `sed`, by escaping `[]/&$.*^\` - syntax:
# `_sed_escape STRING`
_sed_escape() {
	echo "${1}" | sed 's/[]\/&.*$^[]/\\&/g'
}

package() {
	local _sed_subst="
		s/@PACKAGE_NAME@/$(_sed_escape "$pkgname")/g
		s/@PACKAGE_VERSION@/$(_sed_escape "$pkgver")/g
		s/@PACKAGE_RELEASE@/$(_sed_escape "$pkgrel")/g
		s/@PACKAGE_ARCH@/$(_sed_escape "$_archstr")/g
	"

	install -dm 755 "$pkgdir/usr/bin"
	sed "$_sed_subst" "$pkgname.in" > "$pkgdir/usr/bin/$pkgname"
	chmod +x "$pkgdir/usr/bin/$pkgname"

	install -dm 755 \
		"$pkgdir/usr/share/icons/hicolor/scalable/apps" \
		"$pkgdir/usr/share/icons/hicolor/128x128/apps"

	install -Dm 644 "$pkgname.png" \
    "$pkgdir/usr/share/icons/hicolor/128x128/apps/$pkgname.png"
	install -Dm 644 "$pkgname.svg" \
    "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"

	install -dm 755 "$pkgdir/usr/share/applications"
	sed "$_sed_subst" "$pkgname.desktop.in" > \
		"$pkgdir/usr/share/applications/$pkgname.desktop"

	install -Dm 444 "$pkgname-linux-$_archstr-$pkgver.tar.xz" \
		"$pkgdir/opt/$pkgname/$pkgname-$_archstr-$pkgver.tar.xz"
}

